package com.ruoyi.web.controller.api;

import com.ruoyi.common.core.controller.BaseController;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.dp.domain.DpFleetSituation;
import com.ruoyi.dp.domain.DpFlightPlan;
import com.ruoyi.dp.service.IDpDangerousPointService;
import com.ruoyi.dp.service.IDpFleetSituationService;
import com.ruoyi.dp.service.IDpFlightPlanService;
import com.ruoyi.dp.service.IDpSafeOperationService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@Api(description="大屏接口")
@RestController
@RequestMapping("/api/dp")
public class DPController extends BaseController {

    @Autowired
    private IDpSafeOperationService dpSafeOperationService;

    @Autowired
    private IDpDangerousPointService  dpDangerousPointService;

    @Autowired
    private IDpFleetSituationService dpFleetSituationService;

    @Autowired
    private IDpFlightPlanService dpFlightPlanService;

    /**
     * 主大屏 获取安全运行数据
     */
    @RequestMapping("/getSafeOperation")
    public AjaxResult getSafeOperation(){
        return success(dpSafeOperationService.selectDpSafeOperatioinList());
    }

    /**
     * 生产安全监控大屏 - 获取危险点分布数据
     * @return  所有有效点
     */
    @RequestMapping("/getDistribution")
    public AjaxResult getDistribution(){
        return success(dpDangerousPointService.selectDpDangerousPointList());
    }

    /**
     * 商飞快线大屏  -  机队整体情况
     * @return  1条最新数据
     */
    @RequestMapping("/getFleetSituation")
    public AjaxResult getFleetSituation(){
        List<DpFleetSituation> list = dpFleetSituationService.selectDpFleetSituationList(null);
        if (list.size() > 0){
         return success(list.get(0));
        }
        return success(list);
    }

    /**
     * 商飞快线大屏 - 当日飞行计划
     * @return  当日所有计划
     */
    @RequestMapping("/getFlightPlan")
    public AjaxResult getFlightPlan(){
        DpFlightPlan dpFlightPlan = new DpFlightPlan();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dpFlightPlan.setFlightDate(dateFormat.format(new Date()));
        return success(dpFlightPlanService.selectDpFlightPlanList(dpFlightPlan));
    }

}
